<template>
	<view class="content">
		<view v-if="isShowSwiper" class="countdown" @click="skip" >跳过</view>
		<swiper v-if="isShowSwiper" class="swiper-box" 
			@animationfinish="change" 
			indicator-dots="true" 
			indicator-active-color="#2B9939"
			current="0"
			interval="3000"
			duration="500"
			skip-hidden-item-layout="true"
		>
			<swiper-item v-for="(item ,index) in info" :key="index">
				<image class="advertiseImg" :src="item.url" mode="aspectFill" v-if="item.url"/>
				<uni-load-more status="loading" v-if="!item.url" style="margin-top: 20%;"/>
			</swiper-item>
		</swiper>
		<view v-if="!isShowSwiper" style="padding-top: 25%;">
			<uni-load-more status="loading" />
		</view>
	</view>
</template>

<script>
	import config from '../config/config'
	import {mapState,mapMutations,mapActions} from 'vuex'
	import uniSwiperDot from '@/components/uni-ui/uni-swiper-dot/uni-swiper-dot.vue'
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue'
	
	export default {
		components: {uniSwiperDot,uniLoadMore},
	    computed: {
	        ...mapState(['hasLogin', 'forcedLogin'])
	    },
		data() {
			return {
				isShowSwiper:config.isShowAdvertisement,
				info: [
					{url: '../static/img/advertise.jpg'},
					{url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg'},
					{url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/cbd.jpg'},
					{url: ''}
				]
			}
		},
		onShow(){
			if(!this.isShowSwiper){
				this.isLogin();
			}
		},
	    methods: {
			...mapActions(['autoModeLogin']),
			...mapMutations(['login','logout']),
			change(e){
				if(e.detail.current == this.info.length-1){
					this.isShowSwiper = false;
					this.isLogin();
				}
			},
			skip(){
				this.isLogin();
			},
			isLogin(){
				let getParam = (this.$route && this.$route.query) || {};
				if(getParam.access_token && getParam.refresh_token){
					this.login(getParam);
					return false;
				}
				if(this.forcedLogin && !uni.getStorageSync("access_token") ){
					if(config.webMode == 'wx-web' ){
						this.autoModeLogin();
					}else{
						this.login();
					}
				}else{
					uni.switchTab({ url: '/pages/main/main'});
				}
			}
	    }
	}
</script>

<style ​lang="less" scoped>
	.content {
		background-color: #FFFFFF;
		padding: 0;
	}
	.uni-swiper__warp,.swiper-box{
		height: 100%;
	}
	.countdown{
		position: fixed;
		z-index: 1;
		right: 10px;
		top: 45upx;
		padding: 5px;
		border-radius: 100%;
		font-size: 12px;
		color: #fff;
		border: 1px solid #2B9939;
		color: #1B9939;
	}
	.advertiseImg{
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
	}
</style>
